<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
{insert name="module_cssjs" css="core.css" js="jquery.min.js;jquery.blockUI.js"}
</head>
{literal}
<style>
.selectInput {
    border: 1px solid #B9B9B9;
    padding: 5px 3px;
    width: 100px;
	vertical-align:middle;
}
.textarea {
	width: 280px;
	height: 130px;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
	
$('[name="del"]').click(function() {
	var $this = this;
	var id = $(this).parents('tr').attr('node-id');
	if(!id) {
		alert('缺少参数');return ;
	}
	if(!confirm('您确定删除此门票吗？'))return ;
	
	var params = {'id': id};
	$.post('/yunying/product/ticket/del.json', params, function(dt) {
		if(dt.status) {
			alert(dt.message);
		} else {
			$($this).parents('tr').remove();
		}
	}, 'json');
});
$('[name="add"]').click(function() {
	 $.blockUI({ 
         message: $('#infoForm'), 
         css: { 
             top:  ($(window).height() - 400) /2 + 'px', 
             left: ($(window).width() - 400) /2 + 'px', 
             width: '400px' 
         } 
     });
	 $('form[name="infoForm"]').submit(function() {
			var name = $('[name="name"]').val();
			var real_price = $('[name="real_price"]').val();
			var product_id = $('[name="product_id"]').val();
			
			if(!product_id) {
				alert('缺少景点ID');return ;
			}
			if(!name) {
				alert('请输入门票名称');return ;
			}
			if(!real_price) {
				alert('请输入门票出售价格');return ;
			}
			var params = $('form[name="infoForm"]').serialize();
			$.post('/yunying/product/ticket/add.json', params, function(dt) {
				if(dt.status) {
					alert(dt.message);
				} else {
					alert('添加门票成功');
					window.location.href=window.location.href;
				}
			}, 'json');
			return false;
		});
});


$('a[name="edit"]').live('click', function() {
	var $this = this;
	var id = $(this).attr('node-id');
	if(!id) {
		alert('缺少参数');return ;
	}
	var params = {id: id};
	$.post('/yunying/product/ticket/info.json', params, function(dt) {
		if(dt.status) {
			alert(dt.message);
		} else {
			$('input[name="name"]', 'form[name="infoForm"]').val(dt.data.name);
			$('input[name="original_price"]', 'form[name="infoForm"]').val(dt.data.original_price);
			$('input[name="market_price"]', 'form[name="infoForm"]').val(dt.data.market_price);
			$('input[name="real_price"]', 'form[name="infoForm"]').val(dt.data.real_price);
			$('input[name="start_time"]', 'form[name="infoForm"]').val(dt.data.start_time);
			$('input[name="end_time"]', 'form[name="infoForm"]').val(dt.data.end_time);
			$('input[name="num"]', 'form[name="infoForm"]').val(dt.data.num);
			$('textarea[name="description"]', 'form[name="infoForm"]').val(dt.data.description);
			
			$.blockUI({ 
		         message: $('#infoForm'), 
		         css: { 
		             top:  ($(window).height() - 400) /2 + 'px', 
		             left: ($(window).width() - 400) /2 + 'px', 
		             width: '400px' 
		         } 
		     });
			$('form[name="infoForm"]').append('<input name="id" type="hidden" value="'+dt.data.id+'" />')
			$('form[name="infoForm"]').submit(function() {
				var name = $('[name="name"]').val();
				var real_price = $('[name="real_price"]').val();
				var product_id = $('[name="product_id"]').val();
				
				if(!product_id) {
					alert('缺少景点ID');return ;
				}
				if(!name) {
					alert('请输入门票名称');return ;
				}
				if(!real_price) {
					alert('请输入门票出售价格');return ;
				}
				var params = $('form[name="infoForm"]').serialize();
				$.post('/yunying/product/ticket/edit.json', params, function(dt) {
					if(dt.status) {
						alert(dt.message);
					} else {
						alert('编辑门票成功');
						window.location.href=window.location.href;
					}
				}, 'json');
				return false;
			});
		}
	}, 'json');
	return false;
});

$('[name="status"]').click(function() {
	var status = $(this).attr('status');
	var tid = $(this).attr('tid');
	if(!tid) {
		alert('未知门票ID');return ;
	}
	var params = {status: status, id:tid};
	$.post('/yunying/product/ticket/status.json', params, function(dt) {
		if(dt.status) {
			alert(dt.message);
		} else {
			alert('更改门票状态成功');
			window.location.href=window.location.href;
		}
	}, 'json');
});
})
</script>
{/literal}
<body>
<h3 class="label">
	{include file="module/module_ticket.html" flag = "ticket" id=$product_id}
	<span class="refresh"><a href="/yunying/product/">返回列表</a></span>
	<span class="refresh"><a href="">刷新</a></span>
</h3>

<div class="table">
	<div class="desc">
		当前景点：{$info.name}【{$info.province|intToProvinceName} {$info.city|intToCityName:$info.province} {$info.location}】
		<a style="float:right;" name="add" href="javascript:void(0);">添加门票</a>
	</div>
	<table class="TB-list" id="list">
		<tr class="TB-header">
			<td width="50">门票ID</td>
			<td width="270">门票名称</td>
			<td width="60">原价</td>
			<td width="60">进价</td>
			<td width="60">售价</td>
			<td width="60">数量</td>
			<td width="60">剩余数量</td>
			<td width="270">有效期</td>
			<td>操作</td>
		</tr>
		{foreach item=item key=key from=$ticket.data name=$ticket}
		<tr {if $smarty.foreach.list.index%2 == 0}class="even"{else}class="odd"{/if} node-id="{$item.id}">
			<td>{$item.id}</td>
			<td>{$item.name}</td>
			<td>{$item.original_price}</td>
			<td>{$item.real_price}</td>
			<td>{$item.market_price}</td>
			<td>{if $item.num}{$item.num}{else}不限{/if}</td>
			<td>{if $item.last_num}{$item.last_num}{/if}</td>
			<td>{$item.start_time} — {$item.end_time}</td>
			<td>
				[<a name="edit" node-id="{$item.id}" href="javascript:void(0);">编辑</a>]
				{if $item.status == 1}
				[<a name="status" status="0" tid="{$item.id}" href="javascript:void(0);">销售</a>]
				{else}
				[<a name="status" status="1" tid="{$item.id}" href="javascript:void(0);">停止销售</a>]
				{/if}
				[<a href="javascript:void(0);" name="del">删除</a>]</td>
		</tr>
		{/foreach}
	</table>
	<div>{insert name="module_page" query=$query size=$ticket.size num=$ticket.num page=$ticket.page}</div>
</div>

<div class="table" id="infoForm" style="display: none" >
	<form name="infoForm" action="post">
	<input name="product_id" type="hidden" value="{$info.id}" />
	<table class="TB-form">
		<tr>
			<td width="80">门票名称：</td>
			<td><input class="input" name="name" value="" /></td>
		</tr>
		<tr>
			<td width="80">门票原价：</td>
			<td><input class="input" name="original_price" value="" /></td>
		</tr>
		<tr>
			<td width="80">门票进价：</td>
			<td><input class="input" name="real_price" value="" /></td>
		</tr>
		<tr>
			<td width="80">门票售价：</td>
			<td><input class="input" name="market_price" value="" /></td>
		</tr>
		<tr>
			<td width="80">门票数量：</td>
			<td><input class="input" name="num" value="" /></td>
		</tr>
		<tr>
			<td width="80">开售时间：</td>
			<td><input class="input" name="start_time" value="" /></td>
		</tr>
		<tr>
			<td width="80">停售时间：</td>
			<td><input class="input" name="end_time" value="" /></td>
		</tr>
		<tr>
			<td width="80">门票介绍：</td>
			<td>
				<textarea class="textarea" name="description"></textarea>
			</td>
		</tr>
	</table>
	<div class="btn-box">
		<span class="btn-indent"><input class="btn" type="submit" value="保&nbsp;&nbsp;存" /></span>
		<span class="btn-indent"><input onclick="$.unblockUI()" class="btn" type="reset" value="取&nbsp;&nbsp;消" /></span>
	</div>
	</form>
</div>
</body>
</html>